package com.nomito.minimito.controller.front;


import com.nomito.minimito.common.utils.R;
import com.nomito.minimito.entity.ImUserEntity;
import com.nomito.minimito.service.ImUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.omg.PortableInterceptor.INACTIVE;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "前台注册登录系统")
@CrossOrigin
@RestController
@RequestMapping("/front")
public class FLoginController {

    @Autowired
    private ImUserService imUserService;

    @ApiOperation(value = "注册接口")
    @GetMapping("/register")
    public R register(@RequestParam String username,@RequestParam String password ){

        Integer code = imUserService.register(username, password);
        if(code==0){
            return R.error().put("msg","该用户已存在");
        }else if(code==1){
            return R.ok().put("msg","注册成功");
        }else if(code==2){
            return R.error().put("msg","注册失败");
        }else
            return R.error().put("msg","存在异常");
    }


    /**
     * 普通登录方法
     */
    @ApiOperation(value = "登录方法")
    @GetMapping("/login")
    public R login(@RequestParam("username") String username, @RequestParam("password") String password){

        ImUserEntity imUserEntity = imUserService.login(username, password);
        if(imUserEntity!=null){
            return R.ok("登录成功").setData(imUserEntity);
        }else
            return R.error().put("msg","用户名或密码错误");
    }

}
